#ifndef SY_CORE_H
#define SY_CORE_H

#define N 8
#define MAP_SIZE 324 //N * N * 4
#define P_MAP MAP[N+1][N+1]
#define INF (0x7fffffff - 1)
#define MAXS 6561

struct POS {
	int x,y;
	POS *next;
};

struct POS_D {
	int x,y;
	bool dir[8];
};

struct CAN {
	bool *dir;
	int col;
	int deb;
};

namespace MAP{

	//consts
	extern const int DET[8][2];
	//
	extern CAN map_black_dir[N+1][N+1];
	extern CAN map_white_dir[N+1][N+1];

	//useful fuctions
	void Can_drop_black(int P_MAP,POS_D* PUT_POSS_BLACK,POS* BORDER,int &PUT_NUM_BLACK);//create a list
	void Can_drop_white(int P_MAP,POS_D* PUT_POSS_WHITE,POS* BORDER,int &PUT_NUM_WHITE);//create a list

	int Drop_black(int x,int y,int P_MAP,bool dir[6],int Rec[63][2]);
	int Drop_white(int x,int y,int P_MAP,bool dir[6],int Rec[63][2]);
	void Remove_black(int x,int y,int P_MAP,int Rec[63][2]);
	void Remove_white(int x,int y,int P_MAP,int Rec[63][2]);

	void Start(int P_MAP,POS* BORDER,int &PUT_NUM_BLACK,int &PUT_NUM_WHITE,int style);
	void Draw(int P_MAP,int x,int y);
	//

	//about the list
	POS* Find(int x,int y,POS* BORDER);
	void Del(int x,int y,POS* BORDER);
	void Expand(int x,int y,POS* BORDER,int P_MAP);
	void Expand(int x,int y,POS* BORDER,int P_MAP,bool *dir);//AI needs it
	void Resume(int x,int y,POS* BORDER);
	void view(POS*);
	//
}

namespace AI {

	extern const int K_NUM,K_TABL,K_REV;
	extern const int IMP_STEP;
	extern const int V[N+1][N+1];
	extern const int e3[N + 1];
	extern const int fv[N + 1];

	int dfs_dp(int now,int who);
	void Initdp();
	int Get_value(int P_MAP,int B_NUM,int W_NUM,int dep,int who);
	void AI_next(int P_MAP,POS *BD,int NOW_BNUM,int NOW_WNUM,int &Fx,int &Fy);

	int Black_search(int P_MAP,int,int,int,int,int,bool);
	int White_search(int P_MAP,int,int,int,int,int,bool);
	//P_MAP mem used is only about the deepth!
	extern POS* NOW_BORDER;
	extern int f[MAXS][2];
	extern bool calced[MAXS][2];
	extern int MAX_DEP;
	extern int Next_x,Next_y;
};
#endif //SY_CORE_H
